from django.http import HttpResponse, JsonResponse
from django.shortcuts import render

# Create your views here.

def index(request):
    '''
    定义视图
    :param request:
    :return:
    '''
    return HttpResponse('你好骚啊')

def response_header(request):
    '''
    自定义响应头
    :param request:
    :return:
    '''

    response = HttpResponse('好犀利呢')
    response['kfchen'] = 'excellent'

    return response

    pass

def json_responsed(request):
    dict = {'name' : '张三', 'age' : 18}
    dict = ['好犀利呢', 'yes']
    return JsonResponse(data=dict, safe=False)
    pass

def session_demo(request):
    '''
    演示：设置 session，并存放到 redis 中
    :param request:
    :return:
    '''
    request.session.setdefault('name', '张三')

    name = request.session.get('name')
    return HttpResponse(name)
    pass